<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('订单量统计报表')" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<body id="colTb" style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">发货状态</label>
                        <select name="state" id="state" lay-filter="aihao">
                            <option value="">--请选择--</option>
                            <option value="0">全部</option>
                            <option value="1">已发货订单</option>
                            <option value="2">待发货订单</option>
                        </select>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    var functions = [[${functions}]];
    var ids=[];
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate','tablebutton'], function () {
        var myColumns = [];
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var $table;

        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if (ids.length > 0) {
                        arr = $.map(ids, function (Province) {
                            return Province;
                        })
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/ProvincialDynamicReportsController/OrderQuantityStatistics",
                        data: JSON.stringify(object2)
                    });
                }

            }
        });
        //初始化
        zzpUtils.webSocket.init();
        myColumns = getColumns();
        var $table = zzpUtils.table({
                elem: '#table',
                isApi: true,
                pagination: true,
                autoWidth: false,
                scrollX: true,
                data: {state: $('#state').val()},
                url: '/ProvincialDynamicReportsController/Statisticsoforderquantityineach', // 获取数据的地址
                columns: myColumns,
                queryParams: function () {//查询条件
                    return  zzpUtils.getFormJson($("#searchForm"));
                },
                detailFormatter: function (index, row) {
                    return "这里就没有确定过11";
                },onCheck: function (row) {
                btn_cha(row.Province,1);
            },
            onUncheck: function (row) {
                btn_cha(row.Province,1);
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.Province,2);
                });

            },
            onUncheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.Province,3);
                });
            }

        });
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#dataTable");
        })
        function getColumns() {
            var ajaxdata = [];
            // 加载动态表格
            $.ajax({
                url: '/zxsdwms/WmsReportHeaderController/Orderquantityheader',
                type: 'POST',
                dataType: "json",
               data: {state: $('#state').val()},
                async: false,
                success: function (returnValue) {
                    ajaxdata.push({"field": '',
                        "checkbox": true,
                        // 显示复选框
                        "formatter": function (i,row) {
                            // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                            if ($.inArray(row.Province, ids) != -1) {// 因为 判断数组里有没有这个 id
                                return {
                                    "checked": true               // 存在则选中
                                }
                            }

                        }
                    });
                    // 异步获取要动态生成的列
                    var arr = returnValue.rows;
                    $.each(arr, function (i, item) {
                        ajaxdata.push({
                            "field": item.prop,
                            "title": item.label,
                            "hide": true,
                            "align": 'center',
                            "valign": 'middle'
                        });
                });
                    console.log(ajaxdata);
                }
            });
            return ajaxdata;
        }
        $(".inline-reset-btn").on('click',function () {
            $('#state').val("");
        })
    })

    //it 1 反选/勾选 ；2 全选；3全反选
    function btn_cha(id,it) {
        if (it == 1) {

            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            } else {
                ids.push(id);
            }
        } else if (it == 3) {
            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            }

        } else{
            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                }
            }else {
                ids.push(id);
            }
        }
    }

</script>
</html>